//
//  UIView+NavigationBarProperty.m
//  Reader
//
//  Created by yuemei on 2019/4/1.
//  Copyright © 2019 SF. All rights reserved.
//

#import "UIView+NavigationBarProperty.h"

@implementation UIView (NavigationBarProperty)

+ (CGFloat)fixedNavigationBarHeight {
    return 44;
}

+ (CGSize)defalutNavigationBarSize
{
    return CGSizeMake([UIScreen mainScreen].bounds.size.width, self.defalutStatusBarMaxY + self.fixedNavigationBarHeight);
}

+ (CGFloat)defalutNavigationBarHeight
{
    return self.defalutNavigationBarSize.height;
}

+ (CGFloat)defalutStatusBarMaxY
{
    return CGRectGetMaxY([UIApplication sharedApplication].statusBarFrame);
}

- (CGFloat (^)(BOOL))statusBarMaxY {
    return ^(BOOL inevitableExist) {
        CGFloat statusBarMaxY = UIView.defalutStatusBarMaxY;
        if (inevitableExist && statusBarMaxY < FLT_MIN) {
            statusBarMaxY = MAX(self.viewSafeAreaInsets.top, 20);
        }
        return statusBarMaxY;
    };
}

- (CGFloat)defaultTopViewHeight {
    return self.statusBarMaxY(NO) + UIView.fixedNavigationBarHeight;
}

- (CGFloat (^)(BOOL))topViewHeight {
    return ^(BOOL inevitableExist) {
        CGFloat topViewHeight = self.statusBarMaxY(inevitableExist) + UIView.fixedNavigationBarHeight;
        return topViewHeight;
    };
}

@end

@implementation UIView (ViewSafeAreaInsets)

- (UIEdgeInsets)viewSafeAreaInsets
{
    if (@available(iOS 11.0, *)) {
        
        return self.safeAreaInsets;
    }else {
        
        return UIEdgeInsetsZero;
    }
}

@end
